const util = require('../../utils/util.js')
const app = getApp();
Page({
	data: {
		banner: [],
		goods: [],
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth)
	},
	onLoad: function (options) {
		this.loadBanner();
		this.loadMainGoods();
		// this.getInviteCode(options);
	},
	getInviteCode: function (options) {
		// if (options.uid != undefined) {
		// 	wx.showToast({
		// 		title: '来自用户:' + options.uid + '的分享',
		// 		icon: 'success',
		// 		duration: 2000
		// 	})
		// }
	},
	loadBanner: function () {
    let that = this;
    let param = {};
    util.commonRequest('index/Banner/index','post',param,function(res){
       if (res.data.code == 200)
       {
         that.setData({
           banner:res.data.data
         })
       } else{
         wx.showToast({
           title: '服务器异常',
           icon:'none'
         })
       }
    })
	},
	loadMainGoods: function () {
		let that = this;
    let param = {};
    util.commonRequest('index/Goods/index','post',param,function(res){
      if (res.data.code == 200) {
        that.setData({
          goods: res.data.data
        })
      } else {
        wx.showToast({
          title: '服务器异常',
          icon: 'none'
        })
      }
    })
	},
	showDetail: function (e) {
		// var index = e.currentTarget.dataset.index;
		var goodsId = e.currentTarget.dataset.id;
		wx.navigateTo({
      url: "../goods/detail/detail?goodsId=" + goodsId
		});
	},
	showCategories: function () {
		// wx.navigateTo({
		// 	url: "../category/category"
		// });
		wx.switchTab({
			url: "../category/category"
		});
	},
	showOrders: function () {
		wx.navigateTo({
			url: "../order/list/list?status=1"
		});
	},
	onShareApp: function () {
		// return {
		// 	title: '灵动开源电商系统',
		// 	desc: '一个基于LeanCloud开发的开源电商系统',
		// 	path: '/pages/index/index?uid=4719784'
		// }
	},
	showGoods: function (e) {
    var goodsId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../goods/detail/detail?goodsId=" + goodsId
    });
	}
})